package com.zero.rabbitmq.routing;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zero.rabbitmq.utils.ConnectionUtil;
import com.zero.rabbitmq.utils.RabbitConstant;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 天气发布者
 * exchange : direct模式
 */

public class WeatherBureau {

    public static void main(String[] args) throws Exception {

        Map area = new LinkedHashMap<String, String>();
        area.put("china.hunan.changsha.20201127", "中国湖南长沙20201127天气数据");
        area.put("china.hubei.wuhan.20201127", "中国湖北武汉20201127天气数据");
        area.put("china.hunan.zhuzhou.20201127", "中国湖南株洲20201128天气数据");
        area.put("us.cal.lsj.20201127", "美国加州洛杉矶20201127天气数据");

        area.put("china.hebei.shijiazhuang.20201128", "中国河北石家庄20201128天气数据");
        area.put("china.hubei.wuhan.20201128", "中国湖北武汉20201128天气数据");
        area.put("china.henan.zhengzhou.20201128", "中国河南郑州20201128天气数据");
        area.put("us.cal.lsj.20201128", "美国加州洛杉矶20201128天气数据");

        Connection connection = ConnectionUtil.getConnection();

        Channel channel = connection.createChannel();

        /**
         * Params:
         * exchange – the exchange to publish the message to
         * routingKey – the routing key
         * props – other properties for the message - routing headers etc
         * body – the message body
         */

        area.forEach((key,value) ->{
            try {
                channel.basicPublish(RabbitConstant.EXCHANGE_WEATHER_ROUTING,key.toString(),null,value.toString().getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        channel.close();
        connection.close();
    }

}
